<?php
require_once 'Oos.php';

$oos = new Oos("http://localhost/api/v1");
$oos->setCredentials("luis@11870.com", "xx");
$sites = $oos->sites();
$feed = $sites->getSiteFeed('peralta');

function getNextPage($sites, $feed) {
    $nextURL = $feed->getLink('next')->href;

    if ($nextURL !== null) {
        return $sites->getSiteFeed($nextURL);
    } else {
        return null;
    }
}

$tt = "";

do {
	foreach ($feed as $entry) {
		$coords = $entry->getCoordinates();
		$coorarray = split(" ", $coords);
		$description = $entry->getName();
		$lat = $coorarray[0];
		$lon = $coorarray[1];
		$tt .= chr(0x02).pack("V",strlen($description)+14).pack("V",round($lon*100000)).pack("V",round($lat*100000)).$description.chr(0x00);
	}
} while (($feed = getNextPage($sites, $feed)) != null); 

$f = fopen("/tmp/poi", "w");
fwrite($f, $tt);
fclose($f);
